<link rel="stylesheet" href="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/themes/base/jquery.ui.all.css">
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.core.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.widget.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.mouse.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.sortable.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.draggable.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.button.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.resizable.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.position.js"></script>
<script src="<{$smarty.const._DOMAIN_SC_CDN_}>/upload/zx/share/jqueryui/development-bundle/ui/jquery.ui.dialog.js"></script>
<style type="text/css">
.tuan { background: #EEE; width: 1024px; padding: 1em;}
.tuan ul { width: 760px;  overflow: auto; zoom: 1; }
.tuan ul li { 
	margin: 0.5em; 
	border: 1px solid orange; 
	background-color: #aa6; 
	color: blue; 
	width: 160px;
	height: 200px; 
	cursor: move; 
	float: left;
	position: relative;
}
.tuan ul li.holder { width: 160px; height: 200px; background-color: #ABB; border: 1px dotted red; }
.tuan ul li img { width: 150px; height: 150px; border-width: 0; margin-left:5px; margin-top:5px;}
.tuan ul li p { margin: 0; padding: 0; line-height: 20px; height:40px; overflow: hidden; }
.tuan ul li .edit { position: absolute; top: 1em; right: 1em; color: red; cursor: pointer; }
.tuan ul li .del { position: absolute; top: 1em; right: 4em; color: red; cursor: pointer; }


.h-box { width: 1024px; }
</style>
<script type="text/javascript">
var global_curr_item = null;
var global_bef_sid   = 0; //老id
var bef_sid          = 0; //实时修改ID时的临时记录

$(function () {
	$('.tuan .items').disableSelection();
	$('#item-editor').dialog({
		width: 500,
		modal: true,
		autoOpen: false,
		buttons: {
			修改: function () {
				var sId      = $('#item-edit-text-id').val();
				var sTitle   = $('#item-edit-text').val();
				var sImage   = $('#item-edit-image').val();
				var sUrl     = $('#item-edit-url').val();
				var sNprice  = $('#item-edit-now-price').val();
				sNprice      = parseFloat(sNprice);
				sId          = parseInt(sId);

				if( isNaN(sId) || sId<=0 || isNaN(sNprice) || sNprice<=0 || sTitle=='' || sImage=='' || sUrl=='')
				{
					alert('请详细填写内容，标题，图片，外链地址，价格等都不可为空或小于等于0!');
					return false;
				}

				var item      = $(global_curr_item);
				var sOprice   = item.find('.rate').attr('oprice');
				sOprice       = parseFloat(sOprice);
				//判断当前页面找到而且查找gid也不等于当前gid；
				var finditem = $('.columC .right .PP').find("div[gid="+sId+"]");
				if(finditem.length > 0 && finditem.attr('gid') != item.attr('gid'))
				{
					alert('商品修改不能重复！');
					return false
				}

				if(sNprice > sOprice)
				{
					alert('现价不能大于原价！');
					return false;
				}

				item.attr('gid',sId);
				item.find('a.brand-name').html(sTitle);
				item.find('a').attr('title',sTitle);
				item.find('a').attr('href',sUrl);
				item.find('img').attr('alt',sTitle);
				item.find('.fpic img').attr('src', sImage);
				item.find('.rate').attr('price', sNprice);
				item.find('.rate').html('￥'+sNprice+'<i>/</i><del>'+sOprice+'</del>');

				$('#id_'+global_bef_sid).val(sId);
				$('#id_'+global_bef_sid).attr('name','id_'+sId);
				$('#id_'+global_bef_sid).attr('id','id_'+sId);

				$('#input_'+global_bef_sid).val(sTitle);
				$('#input_'+global_bef_sid).attr('name','title_'+sId);
				$('#input_'+global_bef_sid).attr('id','input_'+sId);

				$('#image_'+global_bef_sid).val(sImage);
				$('#image_'+global_bef_sid).attr('name','image_'+sId);
				$('#image_'+global_bef_sid).attr('id','image_'+sId);

				$('#url_'+global_bef_sid).val(sUrl);
				$('#url_'+global_bef_sid).attr('name','url_'+sId);
				$('#url_'+global_bef_sid).attr('id','url_'+sId);

				$('#nowprice_'+global_bef_sid).val(sNprice);
				$('#nowprice_'+global_bef_sid).attr('name','nowprice_'+sId);
				$('#nowprice_'+global_bef_sid).attr('id','nowprice_'+sId);

				$('#position_'+global_bef_sid).attr('name','position_'+sId);
				$('#position_'+global_bef_sid).attr('id','position_'+sId);

				$(this).dialog('close');
			}
		}
	});

	var input_html = '';
	$('.columC .right .PP .goods_main').each (function () {

		var sId       = $(this).attr('gid');
		var sTitle    = $(this).find('a.brand-name').html();
		var sImage    = $(this).find('.fpic img').attr('src');
		var sUrl      = $(this).find('a.brand-name').attr('href');
		var sNprice   = $(this).find('.rate').attr('price');

		input_html += '' 
			+ '<input id="id_'+sId+'" name="id_'+sId+'" value="'+sId+'" type="hidden" />'
			+ '<input id="input_'+sId+'" name="title_'+sId+'" value="'+sTitle+'" type="hidden" />'
			+ '<input id="image_'+sId+'" name="image_'+sId+'" value="'+sImage+'" type="hidden" />'
			+ '<input id="url_'+sId+'" name="url_'+sId+'" value="'+sUrl+'" type="hidden" />'
			+ '<input id="nowprice_'+sId+'" name="nowprice_'+sId+'" value="'+sNprice+'" type="hidden" />'
			+ '';
	});
	$('form .inputs').html(input_html);

	$('.columC .right .PP .goods_main').click(function () {
		$('#item-editor').dialog('open');
		var sId       = $(this).attr('gid');
		var sTitle    = $(this).find('a.brand-name').html();
		var sImage    = $(this).find('.fpic img').attr('src');
		var sUrl      = $(this).find('a.brand-name').attr('href');
		var sNprice   = $(this).find('.rate').attr('price');

		$('#item-edit-text-id').val(sId);
		$('#item-edit-text').val(sTitle);
		$('#item-edit-image').val(sImage);
		$('#item-edit-url').val(sUrl);
		$('#item-edit-now-price').val(sNprice);

		global_curr_item = this;
		global_bef_sid   = sId;
		return false;

	});

	$('#item-edit-text-id').blur( function () {
		var sId = $(this).val();
		bef_sid = global_bef_sid;
		if(bef_sid == sId)
			return false;

		$.get('/home/ajax_goods/'+sId,{ },
			function(o) {
				if(o === null)
				{
					alert('无此商品！');
					$('#item-edit-text-id').val(0);
					return false;
				}

				if(o.goods_id > 0)
				{
					$('#item-edit-text-id').val(sId);
					$('#item-edit-text').val(o.title);
					$('#item-edit-image').val(o.cover_thumb);
					$('#item-edit-url').val(o.url);
					$('#item-edit-now-price').val(o.nowprice);
					var item      = $(global_curr_item);
					item.find('.rate').attr('oprice',o.originalprice);
					bef_sid = sId;
					return true;
				}
			},
			'json'
		);
	});

});

</script>
 
<div class="tuan">
	<{include file="admin/resources/section/demo.tpl"}>
	<div id="item-editor" title="编辑内容" style="width:400px;text-align:left;">
		<p>ＩＤ：<input id="item-edit-text-id" value="" /></p>	
		<p>标题：<input id="item-edit-text" size=50 value="" /></p>	
		<p>图片：<input id="item-edit-image" size=50 value="" style="margin-top:5px;" /></p>	
		<p>链接：<input id="item-edit-url" size=50 value="" style="margin-top:5px;" /></p>	
		<p>现价：<input id="item-edit-now-price" class="in2" type="text" style="width:85px;margin-top:5px;height:20px;line-height:20px;" value=""> 元 &nbsp;&nbsp;&nbsp;&nbsp;
	</div>
</div>
<form action="/home/set_respool_list" id="goods_from" name="frm" method="post">
	<div class="inputs"></div>
	<{foreach from=$goods_list item=it}>
	<input id="position_<{$it.goods_id}>" name="position_<{$it.goods_id}>" type="hidden" value="<{$it.position}>" />
	<{/foreach}>
	<div style="test-align:center;"><input type="submit" value="保存" /></div>
</form>

